home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 4.0 KB | 190 lines | [TEXT/MPS ] |
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __IOCTL__
- #include <IOCtl.h>
- #endif
-
- #ifndef __FCNTL__
- #include <FCntl.h>
- #endif
-
-
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- #ifndef __UFAILURE__
- #include <UFailure.h>
- #endif
-
- typedef long(* GetProcPtr)(void* buffer,
- long count);
- typedef void(* PutProcPtr)(void* buffer,
- long count);
-
- extern "C"
- {
- extern long DevClose(long iop);
- extern long DevIoctl(long iop,
- long cmd,
- void* arg);
- extern long DevFAccess(char* fName,
- long cmd,
- void* arg);
- extern long DevRead(long iop);
- extern long DevWrite(long iop);
- }
-
-
- extern pascal Boolean IsFrontProcess(void);
- extern pascal GetProcPtr SetGetProc(GetProcPtr theGetProc);
- extern pascal PutProcPtr SetPutProc(PutProcPtr thePutProc);
-
- // Global declarations
- extern Boolean pCanEnterDebugger;
- extern long pUDebugInitialized;
- extern long pSegTable;
- extern Str255 pFileName;
-
-
- // Global storage
- Boolean pCanEnterDebugger = FALSE; // Boolean: Debugger can be entered
- long pUDebugInitialized = 0; // Boolean: if Trace unit is inited
- long pSegTable = 0; // HandleListHandle
-
- GetProcPtr pGetProc = NULL; // Address of the PASCAL Proc to Handle Read requests
- // Function DEVGETTEXT(textBuf: Ptr, byteCount: longint): longint;
- PutProcPtr pPutProc = NULL; // Address of the PASCAL Proc to Handle WriteLn requests
- // Procedure DEVPUTTEXT(textBuf: Ptr, byteCount: longint);
-
- Str255 pFileName; // Name of the file to intercept
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- pascal GetProcPtr SetGetProc(GetProcPtr theGetProc)
- {
- GetProcPtr returnProc = pGetProc;
- pGetProc = theGetProc;
- return returnProc;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- pascal PutProcPtr SetPutProc(PutProcPtr thePutProc)
- {
- PutProcPtr returnProc = pPutProc;
- pPutProc = thePutProc;
- return returnProc;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
- long DevClose(long)
- {
- return 0;
- }
-
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevIoctl(long,
- long cmd,
- void*)
- {
- switch (cmd)
- {
- case FIOINTERACTIVE:
- case TIOFLUSH:
- return 0;
-
- default:
- return -1;
- }
- }
-
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevFAccess(char* fName,
- long cmd,
- void*)
- {
- # define CaseSensitive TRUE
- # define DiacritSensitive TRUE
-
- if (EqualString(Str255(fName), pFileName, !CaseSensitive, DiacritSensitive))
- switch (cmd)
- {
- case F_OPEN:
- return 0;
-
- default:
- return -1;
- }
- else
- return -1;
- }
-
-
-
- // !!! Hopefully we can find a real interface for this someday or else do away with it entirely.
-
- struct IOPort
- {
- unsigned char filler[12];
- Ptr bufp;
- long count;
- };
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevRead(long iop)
- {
- IOPort * iopPtr = (IOPort *)iop;
- long bytesRead;
-
- bytesRead = pGetProc(iopPtr->bufp, iopPtr->count);
- iopPtr->bufp += bytesRead;
- iopPtr->count -= bytesRead;
- return 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- long DevWrite(long iop)
- {
- IOPort * iopPtr = (IOPort *)iop;
-
- pPutProc(iopPtr->bufp, iopPtr->count);
- iopPtr->count -= 0;
- return 0;
- }
-
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- pascal Boolean IsFrontProcess(void)
- {
- ProcessSerialNumber frontPSN;
- ProcessSerialNumber applicationPSN;
- Boolean result;
-
-
- FailOSErr(GetCurrentProcess(applicationPSN));
- FailOSErr(GetFrontProcess(frontPSN));
- FailOSErr(SameProcess(frontPSN, applicationPSN, result));
- return result;
- }
-